package lib.common.use;

import java.util.ArrayList;

import org.json.JSONArray;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;

import com.app.BaseActivity;
import com.app.util.Utils_Hardware;
import com.app.view.AutoScrollViewPager;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.viewpagerindicator.LinePageIndicator;
 



// http://www.android100.org/html/201406/04/17771.html
//
//
public class HomeActivity extends BaseActivity {

	
	private HomeActivity activity = this;
	
	private AutoScrollViewPager scrollviewpager;
	private AutoScrollViewAdapter adapter = new AutoScrollViewAdapter();

	private ArrayList<String> listdata = new ArrayList<String>();

 
	
	private PullToRefreshScrollView scroll_view ;
	

	@Override
	public int InitLayout() {
		// TODO Auto-generated method stub
		return R.layout.activity_home;
	}

	@Override
	public void InitView() {
		// TODO Auto-generated method stub
 

		for (int i = 0; i < 3; i++) {
			listdata.add("" + i);
		}

		
		///*  该自定义类，
		scrollviewpager = (AutoScrollViewPager) findViewById(R.id.scrollviewpager);
		scrollviewpager.setAdapter(adapter);
		scrollviewpager.startAutoScroll();
		//*/
		
		
		/*
		  	动态view来根据屏幕适配最合适的大小
		LinearLayout layout_content = (LinearLayout) findViewById(R.id.layout_content);
		int[] size = Utils.getScreenSize(activity);
		scrollviewpager = new AutoScrollViewPager( activity );
		//android.widget.LinearLayout.LayoutParams layout_params = new LayoutParams(size[0], size[1]*2/5);
		android.widget.LinearLayout.LayoutParams layout_params = new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		layout_content.addView(scrollviewpager, layout_params );
		
		// 
		scrollviewpager.setAdapter(adapter);
		scrollviewpager.startAutoScroll();
		*/
		
		///*
		LinePageIndicator   mIndicator = (LinePageIndicator)findViewById(R.id.indicator);
	    mIndicator.setViewPager(scrollviewpager);
		//*/
	    
	    
	    scroll_view = (PullToRefreshScrollView)findViewById(R.id.scroll_view);
	    scroll_view.setOnRefreshListener( new OnRefreshListener<ScrollView>() {

			@Override
			public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
				// TODO Auto-generated method stub
				
			}
		});
 
	    
	    
	    
		
	}

	@Override
	public void InitListener() {
		// TODO Auto-generated method stub

		 
		
	}

	@Override
	public void InitProcess() {
		// TODO Auto-generated method stub

	}

	//
	class AutoScrollViewAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return listdata.size();
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			// TODO Auto-generated method stub
			return arg0 == arg1;
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			// TODO Auto-generated method stub

			View layout_image = getLayoutInflater().inflate(
					R.layout.item_pager_image_black, container, false);
			TextView tv_content = (TextView) layout_image
					.findViewById(R.id.tv_content);
			tv_content.setText(listdata.get(position));
			tv_content.setBackgroundResource(R.drawable.shake_bg_0);
			
			
			int[] size = Utils_Hardware.getScreenSize(activity);
			tv_content.setHeight(size[1]*1/5);
			
			
			container.addView(layout_image, 0);

			return layout_image;
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			// TODO Auto-generated method stub

			container.removeView((View) object);
		}

	};
	
	

}



